﻿Imports Data

Public Class TareasPendientes

    Private Sub btnIngresar_Click(sender As System.Object, e As System.EventArgs) Handles btnIngresar.Click
        Try
            Using db As New SerigraphicaDBDataContext
                Dim tarea As New Data.Tareas_Pendientes
                tarea.nombre = txtNombre.Text
                tarea.descripcion = txtDescripcion.Text
                tarea.fecha_a_realizar = dtFechaArealizarce.Value
                tarea.id_empleado = Me.cbxEncargado.SelectedValue
                tarea.id_estado = 4
                db.Tareas_Pendientes.InsertOnSubmit(tarea)
                db.SubmitChanges()
                MsgBox("Ingresado Correctamente")
                Me.LimpiarInterfaz()
            End Using
        Catch ex As Exception

        End Try
    End Sub

    Private Function LimpiarInterfaz()
        Try
            Me.txtDescripcion.Text = String.Empty
            Me.txtNombre.Text = String.Empty
            Me.cbxEncargado.SelectedValue = 0
            Me.dtFechaArealizarce.Value = Date.Now
        Catch ex As Exception

        End Try
    End Function

    Private Sub TareasPendientes_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        Me.CargarListaResponsable()
    End Sub

    Private Function CargarListaResponsable() As Boolean
        Try
            Using db As New SerigraphicaDBDataContext
                Dim lista As List(Of AbstractObject) = (From x In db.Empleados _
                                                         Select New AbstractObject With {.ID = x.id, _
                                                                                         .Nombre = String.Format("{0} {1} {2}", x.nombre, x.apellido_paterno, x.apellido_materno)}).Distinct.ToList

                Dim manager As BindingManagerBase = Me.cbxEncargado.BindingContext(lista)

                manager.SuspendBinding()
                Me.cbxEncargado.DisplayMember = "Nombre"
                Me.cbxEncargado.ValueMember = "ID"
                Me.cbxEncargado.DataSource = lista
                Me.cbxEncargado.Enabled = True
                manager.ResumeBinding()
            End Using
            Return True
        Catch ex As Exception
            Return False
        End Try
    End Function
End Class